package b3.widget.national
{
	import b3.config.*;
	import b3.net.*;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	import b3.widget.store.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;

	public class ExchangeMonumentItem extends Sprite
	{
		private var permitIndex:int;
		public function ExchangeMonumentItem(permitIndex:int)
		{
			super();
			this.permitIndex = permitIndex;
			var permitConfig:PermitConfig = Config.objConfigs[permitIndex];
			var buildingConfig:BuildingConfig = Config.buildingConfigs[permitConfig.buildingIndex];
			//图片
			var BuildingImage:Class = ResourceHelper.getInstance().getClassByName(buildingConfig.iconImage[0]);
			var buildingImg:Sprite = new BuildingImage();
			buildingImg.mouseEnabled = false;
			buildingImg.width = 50;
			buildingImg.scaleY = buildingImg.scaleX;
			addChild(buildingImg);
			//说明
			var buildingTitleField:TextField = new TextField();
			buildingTitleField.selectable = false;
        	buildingTitleField.autoSize = TextFieldAutoSize.LEFT;
			buildingTitleField.defaultTextFormat = new TextFormat(BFont.fontName, 12, 0x000000);
			buildingTitleField.wordWrap = true;
			buildingTitleField.width = 100;
			buildingTitleField.x = 75;
			buildingTitleField.y = 10; 
			buildingTitleField.text = buildingConfig.name;
			addChild(buildingTitleField);
			
			var priceSprite:Sprite = Store.getPriceSprite("", permitConfig.priceGoldIngot, "NationalStarIcon", 0xFF0000);
			priceSprite.x = 100 - priceSprite.width / 2;
			priceSprite.y = 10;
			addChild(priceSprite);
			
			//另取按钮
			var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgrNational");
			var buttonFetch:BasicButton = new BasicButton(ButtonBgr, "兑换");
			buttonFetch.addEventListener(MouseEvent.CLICK, onButtonExchangeClick);
			buttonFetch.x = 65;
			buttonFetch.y = 60;
			addChild(buttonFetch);
		}
		
		private function onButtonExchangeClick(event:MouseEvent):void
		{
			var purchaseDialog:PurchaseDialog = new PurchaseDialog(permitIndex, 0);
			WidgetManager.getInstance().popOut([purchaseDialog], true);
		}
	}
}